package com.yztc.xiami_app.ui.receiveaddress.presenter;

import android.content.Context;

import com.yztc.xiami_app.bean.ssq.Address;
import com.yztc.xiami_app.ui.receiveaddress.model.IReceiveAddressModel;
import com.yztc.xiami_app.ui.receiveaddress.model.ReceiveAddressModelImpl;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 周旭 on 2016/11/18.
 * "收货地址"的Presenter的实现类
 */

public class ReceiveAddressPresenterImpl implements IReceiveAddressPresenter{

    private IReceiveAddressModel iReceiveAddressModel;

    public ReceiveAddressPresenterImpl(){
        iReceiveAddressModel = new ReceiveAddressModelImpl();
    }

    /**获取显示所有市的列表的Dialog所需要的数据源
     *
     * @param context:上下文
     * @param pName：省份名称
     *  return :   市的列表的数组
     */
    @Override
    public String[] getCityData(Context context, String pName) {
        List<Address> addressList = iReceiveAddressModel.getCities(context, pName);
        //收货的城市列表的数据源
        List<String> mCityList = new ArrayList<>();
        for (Address address:addressList){
            mCityList.add(address.getcName());
        }
        String[] array = mCityList.toArray(new String[mCityList.size()]);
        return array;
    }

    /**
     * 获取显示所有区的列表的Dialog所需要的数据源
     * @param context
     * @param cName：城市名称
     * @return
     */
    @Override
    public String[] getAreaData(Context context, String cName) {
        List<Address> addressList = iReceiveAddressModel.getAreas(context, cName);
        //收货的区列表的数据源
        List<String> mAreaList = new ArrayList<>();
        for (Address address:addressList){
            mAreaList.add(address.getAreaName());
        }
        String[] array = mAreaList.toArray(new String[mAreaList.size()]);
        return array;
    }
}
